package com.sc.nft.admin.controller;

import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dto.IdRequest;
import com.sc.nft.feign.WxMiniProfitTemplateClient;
import com.sc.nft.req.profittemplate.profitTemplateItemPageReq;
import com.sc.nft.req.profittemplate.profitTemplatePageReq;
import com.sc.nft.req.profittemplate.profitTemplateReq;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import com.sc.nft.vo.profittemplate.profitTemplateItemPageVO;
import com.sc.nft.vo.profittemplate.profitTemplatePageVO;
import com.sc.nft.vo.profittemplate.profitTemplateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/wxMiniMall/profitTemplate")
@Api(tags = "小程序分佣模版")
public class WxMiniProfitTemplateController {

    private final WxMiniProfitTemplateClient wxMiniProfitTemplateClient;

    /**
     * 新增小程序分佣模版
     * @param request
     * @return
     */
    @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "小程序分佣模版创建")
    @SysMemberLogin
    public Result saveProfitTemplate(@Valid @RequestBody profitTemplateReq request) {
        return wxMiniProfitTemplateClient.saveProfitTemplate(request);

    }

    /**
     * 更新小程序分佣模版
     * @return
     */
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "小程序分佣模版编辑")
    @SysMemberLogin
    public Result updateProfitTemplate(@Valid @RequestBody profitTemplateReq request) {
        return wxMiniProfitTemplateClient.updateProfitTemplate(request);
    }

    /**
     * 启用小程序分佣模版
     * @param request
     * @return
     */
    @PostMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "启用小程序分佣模版")
    @SysMemberLogin
    public Result enable(@RequestBody IdRequest request) {
        return wxMiniProfitTemplateClient.enable(request);
    }

    /**
     * 关闭小程序分佣模版
     * @param request
     * @return
     */
    @PostMapping(value = "/disable", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "关闭小程序分佣模版")
    @SysMemberLogin
    public Result disable(@RequestBody IdRequest request) {
        return wxMiniProfitTemplateClient.disable(request);
    }


    /**
     * 小程序分佣模版详情
     * @param request
     * @return
     */
    @PostMapping(value = "/details", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "小程序分佣模版详情")
    @SysMemberLogin
    public Result<profitTemplateVO> details(@RequestBody IdRequest request) {
        return wxMiniProfitTemplateClient.details(request);
    }


    /**
     * 小程序分佣模版绑定的商品
     * @param request
     * @return
     */
    @PostMapping(value = "/getGoods", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "小程序分佣模版绑定的商品")
    @SysMemberLogin
    public Result<List<profitTemplateItemPageVO>> getGoods(@RequestBody profitTemplateItemPageReq request) {
        return Result.success(wxMiniProfitTemplateClient.getGoods(request));
    }


    /**
     * 分佣模版列表
     * @param request
     * @return
     */
    @PostMapping(value = "/adminPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分佣模版列表")
    @SysMemberLogin
    public PageResult<profitTemplatePageVO> adminPage(@RequestBody profitTemplatePageReq request) {
        return wxMiniProfitTemplateClient.adminPage(request);
    }

}